package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/micro/go-micro/v2/web"
	"go-micro/framework/gin_"
	"go-micro/src/Boot"
	_ "go-micro/src/lib"
	"log"
	"os"
	"os/signal"
	"strings"
	"syscall"
)

func main() {
	Boot.BootInit()
	router := gin.New()
	gin_.BootStrap(router)
	//启动htt服务， 注册gin的路由
	service := web.NewService(
		web.Name(strings.Join([]string{Boot.JConfig.Service.Namespace, Boot.JConfig.Service.Name}, ".")),
		web.Handler(router),
	)
	err := service.Init()
	if err != nil {
		log.Fatal(err)
	}
	go func() {
		if err = service.Run(); err != nil {
			Boot.BootErrChan <- err
		}
	}()
	go func() {
		sig_c := make(chan os.Signal)
		signal.Notify(sig_c, syscall.SIGINT, syscall.SIGTERM)
		Boot.BootErrChan <- fmt.Errorf("%s", <-sig_c)
	}()
	err = <-Boot.BootErrChan
	fmt.Println(err)
}
